package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzyl.common.utils.StringUtils;
import com.zzyl.nursing.vo.NursingProjectVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目Controller
 *
 * @author syl
 * @date 2025-05-23
 */
@Api(tags = "护理项目")
@RestController
@RequestMapping("/nursing/project")
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @ApiOperation("查询护理项目列表")
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/list")
    public TableDataInfo<NursingProject> list(NursingProject nursingProject)
    {
        startPage();
        LambdaQueryWrapper<NursingProject> queryWrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotEmpty( nursingProject.getName())){
            queryWrapper.like( NursingProject::getName, nursingProject.getName());
        }

        if( nursingProject.getStatus()!=null){
            queryWrapper.eq( NursingProject::getStatus, nursingProject.getStatus());
        }
        // TODO 补充查询条件
        List<NursingProject> list = nursingProjectService.list(queryWrapper);
        return getDataTable(list);
    }



    /**
     * 导出护理项目列表
     */
    @ApiOperation("导出护理项目列表")
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingProject nursingProject)
    {
        LambdaQueryWrapper<NursingProject> queryWrapper = new LambdaQueryWrapper<>();

        if(StringUtils.isNotEmpty( nursingProject.getName())){
            queryWrapper.like( NursingProject::getName, nursingProject.getName());
        }

        if( nursingProject.getStatus()!=null){
            queryWrapper.eq( NursingProject::getStatus, nursingProject.getStatus());
        }

        // TODO 补充查询条件
        List<NursingProject> list = nursingProjectService.list(queryWrapper);



        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }


    /**
     * 获取护理项目详细信息   /nursing/project/all
     */
    @ApiOperation("获取所有护理项目")
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping(value = "/all")
    public R<List<NursingProjectVo>> all()
    {
        return R.ok(nursingProjectService.getAll());
    }


    /**
     * 获取护理项目详细信息   /nursing/project/all
     */
    @ApiOperation("获取护理项目详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping(value = "/{id}")
    public R<NursingProject> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(nursingProjectService.getById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.save(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.updateById(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(nursingProjectService.removeById(id));
    }
}
